//
//  AddressModel.swift
//
//  Created by eme on 2016/12/4
//  Copyright (c) . All rights reserved.
//

import Foundation
import SwiftyJSON
import ModelProtocol

class AddressModel: ModelProtocol {
    
    // MARK: Declaration for string constants to be used to decode and also serialize.
    internal let kAddressCityKey: String = "city"
    internal let kAddressFlagKey: String = "flag"
    internal let kAddressProvinceKey: String = "province"
    internal let kAddressAdressKey: String = "adress"
    internal let kAddressAddidKey: String = "addid"
    internal let kAddressSpidKey: String = "spid"
    internal let kAddressAreaKey: String = "area"
    internal let kAddressCellphoneKey: String = "cellphone"
    internal let kAddressRecipientsKey: String = "recipients"
    internal let kAddressCreatedateKey: String = "createdate"
    internal let kAddressZipcodeKey: String = "zipcode"
    
    
    // MARK: 属性
    var city: String
    var flag: String
    var province: String
    var adress: String
    var addid: String
    var spid: String
    var area: String
    var cellphone: String
    var recipients: String
    var createdate: String
    var zipcode: String
    
    
    
    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    required  init?(json: JSON) {
        city = json[kAddressCityKey].stringValue
        flag = json[kAddressFlagKey].stringValue
        province = json[kAddressProvinceKey].stringValue
        adress = json[kAddressAdressKey].stringValue
        addid = json[kAddressAddidKey].stringValue
        spid = json[kAddressSpidKey].stringValue
        area = json[kAddressAreaKey].stringValue
        cellphone = json[kAddressCellphoneKey].stringValue
        recipients = json[kAddressRecipientsKey].stringValue
        createdate = json[kAddressCreatedateKey].stringValue
        zipcode = json[kAddressZipcodeKey].stringValue
        
    }
    
    
    /**
     Generates description of the object in the form of a NSDictionary.
     - returns: A Key value pair containing all valid values in the object.
     */
    internal func dictionaryRepresentation() -> [String : AnyObject ] {
        
        var dictionary: [String : AnyObject ] = [ : ]
        
        dictionary.updateValue(city as AnyObject, forKey: kAddressCityKey)
        
        dictionary.updateValue(flag as AnyObject, forKey: kAddressFlagKey)
        
        dictionary.updateValue(province as AnyObject, forKey: kAddressProvinceKey)
        
        dictionary.updateValue(adress as AnyObject, forKey: kAddressAdressKey)
        
        dictionary.updateValue(addid as AnyObject, forKey: kAddressAddidKey)
        
        dictionary.updateValue(spid as AnyObject, forKey: kAddressSpidKey)
        
        dictionary.updateValue(area as AnyObject, forKey: kAddressAreaKey)
        
        dictionary.updateValue(cellphone as AnyObject, forKey: kAddressCellphoneKey)
        
        dictionary.updateValue(recipients as AnyObject, forKey: kAddressRecipientsKey)
        
        dictionary.updateValue(createdate as AnyObject, forKey: kAddressCreatedateKey)
        
        dictionary.updateValue(zipcode as AnyObject, forKey: kAddressZipcodeKey)
        
        
        return dictionary
    }
    
    
}
